package com.bw.live_streaming.controller;

import java.util.*;
import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bw.live_streaming.entity.SinatvEntity;
import com.bw.live_streaming.service.SinatvService;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.R;



/**
 * 
 *
 * @author wj
 * @email sunlightcs@gmail.com
 * @date 2021-08-18 20:22:42
 */
@RestController
@RequestMapping("live_streaming/sinatv")
public class SinatvController {
    @Autowired
    private SinatvService sinatvService;

    /**
     * 点击轮播图跳转到直播列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam(value = "page",defaultValue = "1")Integer page,
                  @RequestParam(value = "limit",defaultValue = "2")Integer limit){
        IPage<SinatvEntity> list=sinatvService.getList(page,limit);
        PageUtils pageUtils = new PageUtils(list.getRecords(), (int) list.getTotal(), (int) list.getSize(), (int) list.getPages());
        return R.ok().put("page", pageUtils);
    }

    /**
     * 直播列表
     */
    @RequestMapping("/lists")
    public R list(){
        List<SinatvEntity> list=sinatvService.list();
        return R.ok().put("list", list);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{sinatvId}")
    public R info(@PathVariable("sinatvId") Integer sinatvId){
		SinatvEntity sinatv = sinatvService.getById(sinatvId);

        return R.ok().put("sinatv", sinatv);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SinatvEntity sinatv){
		sinatvService.save(sinatv);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SinatvEntity sinatv){
		sinatvService.updateById(sinatv);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] sinatvIds){
		sinatvService.removeByIds(Arrays.asList(sinatvIds));

        return R.ok();
    }

}
